package Liti.LT_01;

import java.util.Arrays;
import java.util.Scanner;

/*
 * Σb[i]=sum;
 * sum + d* = n&
 * &是b[i]+几个d，也就是最后数组所有元素都相等的那个值
 * *是要求的结果；
 * n& -d*=sum;
 * ax+by=gcd(a,b)
 *
 * */


public class Nd {

    public static void main(String[] args) {
        int n, d;//定义两个数据
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        n *= n;
        d = in.nextInt();//输入n，d
        int[] b = new int[n];//存放数据的数组
        int sum = 0;//计算数组总和
        for (int i = 0; i < n; i++) {
            b[i] = in.nextInt();
            sum += b[i];
        }
        System.out.println(sum);
        int x = gcd(n, -d);
        if (sum % x != 0) {
            System.out.println("-1");
        } else {
            int y = sum / x;
            System.out.println(Arrays.toString(exgcd(n, -d)));
        }


    }

    public static int gcd(int a, int b) {
        //欧几里得算法
        return b == 0 ? a : gcd(b, a % b);
    }

    public static Integer[] exgcd(int a, int b) {
//        扩展欧几里得算法；
        if (b == 0) {
            return new Integer[]{1, 1};
        }
        Integer[] ret = exgcd(b, a % b);
        int t = ret[0];
        ret[0] = ret[1];
        ret[1] = t - a / b * ret[1];
        return ret;
    }
}
